﻿using System;

namespace csharpbiancheng_ch11_example3
{
    class Book : IComparable<Book>
    {
        public string Name { get; set; }
        public double Price { get; set; }
        public Book(string name, double price)
        {
            Name = name;
            Price = price;
        }
        //实现比较器比较的方法
        public int CompareTo(Book other)
        {
            return (int)(this.Price - other.Price);
        }
        //重写ToString方法，返回图书名称他价格
        public override string ToString()
        {
            return Name + ";" + Price;
        }
        //图书信息排序
        public static void BookSort(Book[] books)
        {
            Array.Sort(books);
        }
    }
    class Program
    {
        //定义对图书信息排序的委托
        public delegate void BookDelegate(Book[] books);

        static void Main(string[] args)
        {
            BookDelegate bookDelegate = new BookDelegate(Book.BookSort);
            Book[] book = new Book[3];
            book[0] = new Book("计算机应用", 50);
            book[1] = new Book("C# 教程", 59);
            book[2] = new Book("VS2015应用", 49);
            bookDelegate(book);

            foreach (Book bk in book)
            {
                Console.WriteLine(bk);
            }
        }
    }
}
